/**
* Author: CZ cz.theng@gmail.com
 */

package main

/*
#include <stdlib.h>
#include <stdio.h>
*/
import "C" // must be here not in ()

import (
	"fmt"
	"time"
	"unsafe"
)

func cprint(s string) {
	cs := C.CString(s)
	C.fputs(cs, (*C.FILE)(C.stdout))
	C.free(unsafe.Pointer(cs))
}

func random() int {
	return int(C.random())
}

func seed(i int) {
	C.srandom(C.uint(i))
}

func main() {
	println("Invoke glibc from golang")
	s := time.Now().Nanosecond()
	fmt.Println("Set seed ", s)
	seed(s)
	r := random()
	fmt.Println("Random r is ", r)
	str := "string"
	cprint(str)

}
